package br.com.tcc.jpa;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.hibernate.Session;

public class DataBaseManagerSingleton {


	private static DataBaseManagerSingleton entityManager = new DataBaseManagerSingleton();
	
	private DataBaseManagerSingleton() {
		
	}

	public static DataBaseManagerSingleton getEntityManager(){
		return entityManager;
	}
	
	protected static EntityManagerFactory entityManagerFactory;

	protected static Session session;

		
	public static void boot() {
		entityManagerFactory = Persistence.createEntityManagerFactory("jpaPu");
		entityManager = (DataBaseManagerSingleton) entityManagerFactory.createEntityManager();
		session = (Session) ((EntityManager) entityManager).getDelegate();
	}
	public static void shutdown() {
		if (((EntityManager) entityManager).isOpen())
			((EntityManager) entityManager).close();
		entityManagerFactory.close();
	}
	/*	metodo onde feito o tratamento de abrir e fechar sessao, 
	quando uma transacao eh aberta, finalizada*/

}